﻿using System;
using System.Text.RegularExpressions;

namespace Util.TitleParser
{
    //Format S01E08
    class Parse_SssEee : ITitleParser
    {
        public void ParseTitle(string Title, out string Name, out string Details, out long Season, out long Episode)
        {
            Match m = Regex.Match(Title, "[sS][0-1][0-9][eE][0-3][0-9]");
            if (!m.Success)
            {
                throw new ArgumentException("Couldn't parse Title", "Title");
            }

            Season = long.Parse(m.Value.Substring(1, 2), System.Globalization.CultureInfo.InvariantCulture);
            Episode = long.Parse(m.Value.Substring(4, 2), System.Globalization.CultureInfo.InvariantCulture);
            try
            {
                Name = Title.Substring(0, m.Index - 1);
            }
            catch (Exception)
            {
                Name = Title;
            }

            try
            {
                Details = Title.Substring(m.Index + 6);
            }
            catch (Exception)
            {
                Details = Title;
            }
        }
    }
}
